package com.jadesoft.ciadapter.template;

import java.io.File;
import java.io.IOException;
import java.util.Locale;

import javax.servlet.ServletException;

import org.apache.struts.action.ActionServlet;
import org.apache.struts.config.ModuleConfig;

import com.jadesoft.ciadapter.plugin.base.PluginManager;

import freemarker.template.Configuration;
import freemarker.template.DefaultObjectWrapper;

public class FreeMarkerPlugin implements org.apache.struts.action.PlugIn{

	public void destroy() {
		// TODO Auto-generated method stub
		
	}

	@SuppressWarnings("deprecation")
	public void init(ActionServlet arg0, ModuleConfig arg1)
			throws ServletException {
		// TODO Auto-generated method stub
		
		Configuration cfg = Configuration.getDefaultConfiguration();
		// 指定一个加载模版的数据源 
		// 这里我设置模版的根目录 
		try {
			cfg.setDirectoryForTemplateLoading(new File(arg0.getServletContext().getRealPath("/templates")));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
		cfg.setEncoding(Locale.CHINA, "UTF-8");
		// 指定模版如何查看数据模型.这个话题是高级主题... 
		// 你目前只需要知道这么用就可以了: 
		cfg.setObjectWrapper(new DefaultObjectWrapper());
		
		
		PluginManager.context = arg0.getServletContext();
		
	}

}
